package mobi.hami.huapin.service.impl;

import mobi.hami.huapin.base.Result;
import mobi.hami.huapin.dao.NoteThumbUpLogMapper;
import mobi.hami.huapin.model.NoteThumbUpLog;
import mobi.hami.huapin.service.NoteThumbUpLogService;
import mobi.hami.huapin.util.Results;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;


@Service
public class NoteThumbUpLogServiceImpl implements NoteThumbUpLogService {

    private static final Logger logger = LoggerFactory.getLogger(CourierServiceImpl.class);

    @Autowired
    private NoteThumbUpLogMapper noteThumbUpLogMapper;

    public Result addNoteThumbUpLog(Integer userId, Integer noteId){
        if(null == userId || null == noteId){
            return Results.failure("userId or noteId is null");
        }
        //验证该纸条被踢贴记录是否存在
        //...
        NoteThumbUpLog ntu = noteThumbUpLogMapper.findOneBy(userId,noteId);
        if(null != ntu){
            return Results.failure("您已经点过赞了");
        }
        NoteThumbUpLog ntul = new NoteThumbUpLog(noteId,userId,new Date());
        int i = noteThumbUpLogMapper.insert(ntul);
        if(i > 0){
            return Results.success();
        }
        return Results.failure();
    }


}
